#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

/*function... might want it in some class?*/
int getdir (string dir, vector<char*> &files) {
	DIR *dp;
	struct dirent *dirp;
	if((dp = opendir(dir.c_str())) == NULL) {
		cout << "Error(" << errno << ") opening " << dir << endl;
		return errno;
	}

	while ((dirp = readdir(dp)) != NULL) {
		if (dirp->d_name[0] != '.'){
			files.push_back(dirp->d_name);
		}
	}
	closedir(dp);
	return 0;
}

void openPointers(vector<FILE*> filePointers, vector<char*> files, int start, int cant){
	for (int i = 0; i<= cant; i++){
		filePointers[i] = fopen(strcat("./",files[i]),"r");
	}

}

void closePointers(vector<FILE*> filePointers, int cant){
	for (int i = 0; i<= cant; i++){
		fclose(filePointers[i]);
	}

}

int main()
{
	string dir = string(".//texts");
	vector<char*> files = vector<char*>();

	vector<FILE*> filePointers = vector<FILE*>();

	getdir(dir,files);

	//temporal para testear, esto se determina algorítmicamente
	int start = 0;
	int cant = 2;
	openPointers(filePointers, files, start, cant);

	//acá va la parte del heap (pendiente)

	closePointers(filePointers, cant);



	return 0;
}
